package com.gonsin.gmessage.logic.swagger;

import com.github.xiaoymin.knife4j.core.extend.OpenApiExtendSetting;
import com.github.xiaoymin.knife4j.spring.configuration.Knife4jProperties;
import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
import com.gonsin.gmessage.logic.GMessage;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties({Knife4jProperties.class})
@ConditionalOnProperty(name = "knife4j.enable",havingValue = "true")
public class GMessageSwaggerConfig {

    @Bean(initMethod = "start")
    @ConditionalOnMissingBean(GMessageOpenApiExtensionResolver.class)
    @ConditionalOnProperty(name = "knife4j.enable",havingValue = "true")
    public GMessageOpenApiExtensionResolver gmessageOpenApiExtensionResolver(Knife4jProperties knife4jProperties){
        OpenApiExtendSetting setting=knife4jProperties.getSetting();
        if (setting==null){
            setting=new OpenApiExtendSetting();
        }
        return new GMessageOpenApiExtensionResolver(setting, knife4jProperties.getDocuments());
    }

}
